package ModelLayer;
import java.util.ArrayList;


/**
 * keeps info about: a product, employee and costumer. 
 * 
 * @author Team Black 
 * @version 1.0
 */
public class Ordre
{
    // instance variables - replace the example below with your own
    static int runningOrderId;
    private int orderId;
    private String status;
    private double total;
    private ArrayList<PartOrdre> partOrders;
    private Customer customers;
    private Employee employees;

    public Ordre()
    {
        partOrders = new ArrayList<PartOrdre>();
        runningOrderId++;
        orderId = runningOrderId;
        status = "";
        total = 0;
    }
    
    /**
     * mutator and accessor for the fields; orderID, status, employee, Costumer and totalprice
     */    
    public int getOrderId()
    {
        return orderId;
    }
//     public void setDate(String _date)
//     {
//         date = _date;
//     }
//     public String getDate()
//     {
//         return date;
//     }
    public void setStatus(String _status)
    {
        status = _status;
    }
    public String getStatus()
    {
        return status;
    }
    public void setCustomers(Customer _customer)
    {
        customers = _customer;
    }
    public Customer getCustomer()
    {
        return customers;
    }
    public void setEmployee ( Employee _employee)
    {
        employees = _employee;
    }
    public Employee getEmployee()
    {
        return employees;
    }
    /**
     * returns a total price.
     */
    public double getTotal()
    {
        double price = 0;
        total = price;
        for(PartOrdre ptOrdre : partOrders)
        {
            price =+ ptOrdre.getPrice();
        }
        return price;
    }    
    /**
     * adds a partorder to the container
     */
    public void addPartOrdre(PartOrdre _partOrder)
    {
        partOrders.add(_partOrder);
    }
    /**
     * removes a partorder from the container
     */
    public void removePartOrdre(PartOrdre _partOrder)
    {
        partOrders.remove(_partOrder);
    }
    
    public PartOrdre searchById(int _id)
    {
        PartOrdre retpartOrdre = null;
        int index = 0;
        boolean found = false;
        
        while(index < partOrders.size() && !found)
        {
            PartOrdre currPartOrdre = partOrders.get(index);
            if(currPartOrdre.getNumber() == _id)
            {
                retpartOrdre = currPartOrdre;
                found = true;
            }
            else
            {
                index++;
            }
        }
        return retpartOrdre;
    }
    public PartOrdre searchPartOrdreByProduct(Product _product)
    {
        PartOrdre retPartOrdre = null;
        int index = 0;
        boolean found = false;
        
        while(index < partOrders.size() && !found)
        {
            PartOrdre currPartOrdre = partOrders.get(index);
            if(currPartOrdre.getProduct().equals(_product))
            {
                retPartOrdre = currPartOrdre;
                found = true;
            }
        
        else
        {
            index++;
        }
        }
        return retPartOrdre;
    }
}
